#{extends 'main.html' /}
#{set title:'财务管理' /}
*{<script type="text/javascript" src="/public/sui/js/list.js"></script>}*
  <body>
    <div class="page-group">
      <div class="page">
        <header class="bar bar-nav">
             <a href="javascript:history.go(-1);" class="icon icon-left pull-left"></a>
             <h1 class="title">财务管理</h1>

        </header>
        <section class="content withdrawal scroll_y">
            <ul>
                <li><strong>总金额：</strong>

                 #{if merchant.frozenAmount == null && merchant.withdrawalsAmount == null} 0#{/if}
                 #{if merchant.frozenAmount != null && merchant.withdrawalsAmount != null}    ${(merchant.frozenAmount + merchant.withdrawalsAmount).format('#.##')} #{/if}
                #{if merchant.frozenAmount == null && merchant.withdrawalsAmount != null}    ${merchant.withdrawalsAmount.format('#.##')} #{/if}
                </li>
                <li><strong>待提现金额：</strong> <a *{href="/bill/frozenBillList"}* onclick="showFrozen()"><em>查看</em></a>${merchant.frozenAmount == null? 0:merchant.frozenAmount.format('#.##')}  </li>
                <li><strong>可提现金额：</strong><span id="normalAmount">${merchant.withdrawalsAmount == null? 0: merchant.withdrawalsAmount.format('#.##')}</span></li>
                <li><strong>收入明细：</strong><a *{href="/finance/info" external}* onclick="showFinance()" ><em>查看</em></a></li>
                <li><strong>收款人：</strong>
                    #{if  webUser==null}
                        <a href="/bill/bindingUser" external class="button button-link button-fill button-pink button-small">绑定手机号</a>
                    #{/if}
                    #{if  webUser!=null} ${webUser?.nickName}#{/if}
                </li>
            </ul>
            <div class="content-block">
              <input type="button" class="button button-fill  button-big" value="提现" />
            </div>

        </section>


      #{include 'footer.html'/}
      </div>   
        <div class="popup popup-about" style="top:50%;">
            <div class="content-block" style="padding: 0.5rem;">
                <input readonly id="sureMoney" name="sureMoney" placeholder="可提现金额" value="${merchant.withdrawalsAmount == null ? 0:merchant.withdrawalsAmount.format('#.##')}" style="width: 100%; height:2rem; line-height: 1.8rem; text-indent: 0.2rem; border: 1px #eeeeee solid; margin: 0.5rem 0;">
                <input type="number" id="money" name="money" placeholder="提现金额" style="width: 100%; height:2rem; line-height: 1.8rem; text-indent: 0.2rem; border: 1px #eeeeee solid; margin: 0.5rem 0;">
                <input type="button" class="button button-fill  button-big" onclick="withdrawals()" value="确认提现" />
            </div>
        </div>
    </div>
    *{#{include 'weixin/temp/tixian.html'/}}*
    <script>$.init();</script>
    <script type="text/javascript">


        $(document).on('click','.button', function () {
            $.popup('.popup-about');
        });
        $(document).on('click','.popup-overlay', function () {
            $("#money").val('');
            $.closeModal('.popup-about')
        });
        function  showFinance() {

            $.router.load('/finance/info', false);
        }

        function  showFrozen() {

            $.router.load('/bill/frozenBillList', false);
        }

        function withdrawals() {
            var money = $("#money").val();
            var sureMoney = $("#sureMoney").val();
            var reg = /^\d{1,8}$/;
            if(parseInt(money)>parseInt(sureMoney)){
                $.toast('提现金额已超出');
                return ;
            }
            if(parseInt(money) == 0){
                $.toast('提现金额不能为0');
                return ;
            }
            if(!reg.test(money)){
                $.toast('提现金额只能为1-8位整数');
                return ;
            }
            console.log("amount",parseInt(money));
            $.getJSON('/bill/withdrawals',{ amount:parseInt(money)},function (data) {
                    console.log(data);
                    console.log("data.success",data.success);
                if(data.success){
                    $.toast(data.msg)
                    $.closeModal('.popup-about')
                    $("#money").val('');
                    document.location.href = "/bill/index";
                }else{
                    $.toast(data.msg)
                    $.closeModal('.popup-about')
                    $("#money").val('');
                }
             })
        }

    </script>
  </body>
